package org.jeecg.common.util;

import cn.hutool.core.codec.Base64;
import cn.hutool.http.HttpException;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import javax.annotation.PostConstruct;
import java.io.ByteArrayInputStream;
import java.util.Date;
import java.util.Iterator;
import java.util.UUID;

@Component  // 交由spring管理
public class OnlinePicUtil {





    public static String getBase64ByUrl(String url) {
        HttpResponse httpResponse = HttpRequest.get(url).timeout(3000).execute();
        if (200 == httpResponse.getStatus()) {
            return Base64.encode(httpResponse.bodyBytes());
        } else {
            throw new HttpException("图片请求失败,url" + url);
        }
    }


    public static void main(String[] args) {
        System.out.println(getBase64ByUrl("https://cxzdjs.oss-cn-hangzhou.aliyuncs.com/upload/1628692977333_1628693084658.mp4"));
    }


}
